package com.fujimana.rockincat.restree.init;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;


public abstract class AbstractDeployer<T> implements Deployer<T> {
	
	private String[] resources;
	
	protected AbstractDeployer(String[] resources) {
		this.resources = resources;
	}

	@Override
	public final List<T> scan() {
		List<T> deployment = new ArrayList<T>();
		
		Scanner scanner = getScanner();
		
		for(String res : resources) {
			File f = new File(res);
			
			if(f.isDirectory()) {
				scanner.scanDirectory(f);
			} else {
				scanner.scanResource(res);
			}
			
		}
		
		Set<String> result = scanner.getResult();
		Handler<T> handler = getHandler();
		
		for(String str : result) {
			if(handler.isHandle(str)) {
				deployment.add(handler.handle(str));
			}
			
		}
		
		return deployment;
	}

}
